package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurBindFiles;
import com.js.purs.service.IPurBindFilesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 招标文件Controller
 * 
 * @author lzq
 * @date 20240626
 */
@RestController
@RequestMapping("/bindFiles")
public class PurBindFilesController extends BaseController
{
    @Autowired
    private IPurBindFilesService purBindFilesService;

    /**
     * 查询招标文件列表
     */
    @RequiresPermissions("purs:bindFiles:list")
    @GetMapping("/list")
    public TableDataInfo list(PurBindFiles purBindFiles)
    {
        startPage();
        List<PurBindFiles> list = purBindFilesService.selectPurBindFilesList(purBindFiles);
        return getDataTable(list);
    }

    /**
     * 导出招标文件列表
     */
    @RequiresPermissions("purs:bindFiles:export")
    @Log(title = "招标文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurBindFiles purBindFiles)
    {
        List<PurBindFiles> list = purBindFilesService.selectPurBindFilesList(purBindFiles);
        ExcelUtil<PurBindFiles> util = new ExcelUtil<PurBindFiles>(PurBindFiles.class);
        util.exportExcel(response, list, "招标文件数据");
    }

    /**
     * 获取招标文件详细信息
     */
    @RequiresPermissions("purs:bindFiles:query")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(purBindFilesService.selectPurBindFilesByFileId(fileId));
    }

    /**
     * 新增招标文件
     */
    @RequiresPermissions("purs:bindFiles:add")
    @Log(title = "招标文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurBindFiles purBindFiles)
    {
        return toAjax(purBindFilesService.insertPurBindFiles(purBindFiles));
    }

    /**
     * 修改招标文件
     */
    @RequiresPermissions("purs:bindFiles:edit")
    @Log(title = "招标文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurBindFiles purBindFiles)
    {
        return toAjax(purBindFilesService.updatePurBindFiles(purBindFiles));
    }

    /**
     * 删除招标文件
     */
    @RequiresPermissions("purs:bindFiles:remove")
    @Log(title = "招标文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds)
    {
        return toAjax(purBindFilesService.deletePurBindFilesByFileIds(fileIds));
    }


    /**
     * 删除招标文件
     */
    @RequiresPermissions("purs:bindFiles:remove")
    @Log(title = "招标文件", businessType = BusinessType.DELETE)
    @DeleteMapping("delFileNameByBindCode/{bindCode}")
    public AjaxResult delFileNameByBindCode(@PathVariable("bindCode") String bindCode)
    {
        return toAjax(purBindFilesService.deletePurBindFilesByBindCode(bindCode));
    }

    /**
     * 删除单个招标文件
     */
    @RequiresPermissions("purs:bindFiles:remove")
    @Log(title = "招标文件", businessType = BusinessType.DELETE)
    @GetMapping("/removeBindFile/{fileName}")
    public AjaxResult removeBindFileByFileName(@PathVariable("fileName") String fileName)
    {
        return toAjax(purBindFilesService.deletePurBindFilesByFileName(fileName));
    }

    @GetMapping("/getBindFilesListBySup/{bindCode}")
    public AjaxResult getBindFilesListBySup(@PathVariable("bindCode") String bindCode){

        return success(purBindFilesService.selectPurBindFilesListBySup(bindCode));
    }
}
